﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<Post>>" %>
<%@ Import Namespace="FeaturesBlog.Models" %>
 <% foreach (Post p in ViewData.Model)
    { %>
        <div class="postIndex">
            <%=Html.ActionLink(Html.Encode(p.PostSubject.ToString()), "Comments", "Post", new { id = p.PostId }, new { tabIndex = p.PostId })%>
        </div>
 <% } %>

 <div id="hiddenPost" class="helper hide">
 </div>

<script type="text/javascript" language="JavaScript">

    var contentIsLoadFor = 0;

    jQuery(document).ready(function () {
        $("div.postIndex > a").hover(callPostAsync, hideHelper);
        $(document).mousemove(function (e) {
            var p = $('#hiddenPost');
            if (p.hasClass("show")) {
                p.css('left', e.pageX - 50);
                p.css('top', e.pageY - 80);
            }
        });
    })

    function getPost(post) {
        var v = $('#hiddenPost');
        v.html(post);
    }

    function callPostAsync() {
        var v = $('#hiddenPost');
        v.removeClass('hide').addClass('show');
        var id = $(this).attr('tabIndex');
        if (contentIsLoadFor != id) {
            $.get("/Post/GetPost", { id: id }, getPost);
            contentIsLoadFor = id;
        }
    }

    function hideHelper() {
        $('#hiddenPost').removeClass('show').addClass('hide');
    }
</script>
 

